package com.sunfeng.chap2.p13;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @Author : 孙峰
 * @Description: shared 是否共享
 * @Date : 2021/10/9  15:39
 */
public class Test13_1 {
    public static void main(String[] args) throws IOException, InterruptedException {
        RandomAccessFile file = new RandomAccessFile("d:\\nio\\a.txt", "rw");
        FileChannel fileChannel = file.getChannel();

        System.out.println("A begin");
        fileChannel.lock(1, 2, false);
        System.out.println("A end");
        Thread.sleep(Integer.MAX_VALUE);
        file.close();
        fileChannel.close();
    }
}
